﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BackboneTest.Models;
using BackboneTest.DAL;
using System.Data;
using SystemCommon;

namespace BackboneTest.BLL
{
    public class TB_UserBLL
    {
        TB_UserDAL dal = new TB_UserDAL(SysConfig.DBConstr);
        public TB_UserBLL()
        { }

        #region  成员方法

                
                 /// <summary>
                /// 增加一条数据
                /// </summary>
                public bool Add(TB_User model)
                {
                    if (dal.Add(model) == -1)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }

                
       
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(TB_User model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int intID)
        {

            return dal.Delete(intID);
        }
        
        /// <summary>
        /// 删除多条数据
        /// </summary>
        public bool Delete(string IDs)
        {

            return dal.Delete(IDs);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TB_User GetModel(int intID)
        {

            return dal.GetModel(intID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TB_User GetModel(string loginID, string pwd)
        {

            return dal.GetModel(loginID,pwd);
        }

          /// <summary>
        /// 判断是否存在该登录账号
        /// </summary>
        /// <param name="loginID"></param>
        /// <returns></returns>
        public bool Exists(string loginID)
        {
            return dal.Exists(loginID);
        }


        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public TB_User Register(TB_User model)
        {

            if (Exists(model.LoginID))
            {
                return null;
            }
            else
            {
                int id = dal.Add(model) ;

                if (id != -1)
                {
                    model.ID = id;
                    return model;
                }
                else
                {
                    return null;
                }
            }

        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataTable GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataTable GetList()
        {
            return dal.GetList();
        }
        
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="TB_UserItem"></param>
        /// <param name="pageSize"></param>
        /// <param name="index"></param>
        /// <param name="Total"></param>
        /// <returns></returns>
        public DataTable GetList(TB_UserItem searchItem, int pageSize, int index, out int Total)
        {
            return dal.GetList(searchItem,pageSize,index,out Total);
        }
        
        /// <summary>
        /// 导入Excel数据
        /// </summary>
        /// <param name="dtExcel"></param>
        /// <returns></returns>
        public bool ExcelToDataBase(DataTable dtExcel)
        {
            return dal.ExcelToDataBase(dtExcel);
        }
        
        #endregion  成员方法
    }
}



